package com.toe.user.webapi.controller;


import com.google.gson.internal.$Gson$Preconditions;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.entity.commodity.CommodityGoods;
import com.toe.pojo.vo.commodity.CommodityClassVO;
import com.toe.pojo.vo.commodity.GoodsListDetailsVO;
import com.toe.pojo.vo.recommend.RecommendCommodityVO;
import com.toe.user.webapi.service.impl.UserHistoryServiceImpl;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 陶涛
 * @since 2022-07-19
 */

@RestController
@RequestMapping("/webapi/user-history")
public class UserHistoryController {
    @Autowired
    UserHistoryServiceImpl historyService;


    @GetMapping("/deletedAllHistoryByUserId")
    @ApiOperation("清空历史记录根据用户id")
    public JsonResult deletedAllHistoryByUserId(Long userId) {
        historyService.deletedAllHistoryByUserId(userId);
        return JsonResult.ok("清空完成了");
    }


    @GetMapping("/getUserGoodsHistoryByUserId/{id}")
    @ApiOperation("查询用户的商品的浏览记录")
    public JsonResult<List<RecommendCommodityVO>> getUserGoodsHistoryByUserId(@PathVariable("id") Long userId) {
        List<Long> goodsIdList = historyService.listGoodsById(userId);
        List<RecommendCommodityVO> goodsList = historyService.getGoodsByGoodsIdList(goodsIdList);
        return JsonResult.ok("查询完成", goodsList);
    }


    @GetMapping("/getUserClassHistoryByUserId/{id}")
    @ApiOperation("查询用户的课程的浏览记录")
    public JsonResult<List<CommodityClassVO>> getUserClassHistoryByUserId(@PathVariable("id") Long userId) {
        List<Long> classIdList = historyService.listClassByUserId(userId);
        List<CommodityClassVO> classList = historyService.listClassByListClassID(classIdList);
        return JsonResult.ok("查询完成", classList);
    }
}

